package org.icrisat.mbdt.ui.wizards;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.internal.resources.ModelObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Model;
import org.icrisat.mbdt.database.DBConnection;
import org.icrisat.mbdt.gef.views.GraphicalView;
import org.icrisat.mbdt.model.RootModel;
import org.icrisat.mbdt.model.GenotypeModel.GenotypeMarkers;
import org.icrisat.mbdt.model.TargetGenotype.TargetGeno;
import org.icrisat.mbdt.model.loader.GenotypeDataLoader;
import org.icrisat.mbdt.model.loader.LinkageMapDataLoader;
import org.icrisat.mbdt.model.loader.QTLDataLoader;
import org.icrisat.mbdt.model.sessions.Session;
import org.icrisat.mbdt.model.sessions.SessionTargetGenotype;
import org.icrisat.mbdt.ui.views.AccessionListView;
import org.icrisat.mbdt.ui.views.SelectedAccessionsView;

/**
 * SwapnaNair 22nd December 2009
 **/
public class LoadDBImportWizard extends Wizard implements IImportWizard {
	
	Connection con = null;
	Statement stmt =null;
	ResultSet rs = null;
	Statement stmtRef =null;
	ResultSet rsRef = null;
	Statement stmtMarker =null;
	ResultSet rsMarker = null;
	Statement stmtAcc =null;
	ResultSet rsAcc = null;
	Statement stmtAllele =null;
	ResultSet rsAllele = null;
	Statement stmtMap =null;
	ResultSet rsMap = null;
	Statement stmtQTL =null;
	ResultSet rsQTL = null;
	Statement stmtSelAcc = null;
	ResultSet rsSelAcc = null;
	Statement stmtTargetGeno = null;
	ResultSet rsTargetGeno = null;
	Statement stmtTargetGeno1 = null;
	ResultSet rsTargetGeno1 = null;
	Statement stmtTargetAllele = null;
	ResultSet rsTargetAllele = null;
	
	int projectId = 0;
	int generationId = 0;
	int ploidy = 0;
	String datasetId = "";
	List<String> accNameList = new ArrayList<String>();
	HashSet<Integer> accIdHashSet = new HashSet<Integer>();
	List<Integer> accIdList = new ArrayList<Integer>();
	List<String> markerNameList = new ArrayList<String>();
	HashSet<Integer> markerIdHashSet = new HashSet<Integer>();
	List<Integer> markerIdList = new ArrayList<Integer>();
	List<Integer> alleleIdList = new ArrayList<Integer>();
	List<String> completeList = new ArrayList<String>();
	String strLink ="";
	String[] arrCompList = null;
	String folder = "";
	String genoTxtFile = "";
	String linkageTxtFile = "";
	String QTLTxtFile = "";
	int countChk = 0;
		
	HashMap<String, Object> selAccHashMap = new HashMap<String, Object>();
	List<Object> selAccList = new ArrayList<Object>();
	HashMap<String, Integer> selAccHashMap1 = new HashMap<String, Integer>();
	List<String> selAccNamesList = new ArrayList<String>();
	HashMap<Object, Object> targetHashMap = new HashMap<Object, Object>();
	List<Object> targetGenoList = new ArrayList<Object>();
	private ScrollingGraphicalViewer graphicalViewer;
	private GenotypeMarkers genoMarkers;
	List<EditPart> editParts = new ArrayList<EditPart>();
	List<String> targetAlleles = new ArrayList<String>();
	List<String> targetCombAlleles = new ArrayList<String>();
	List<String> targetMACCombiValues = new ArrayList<String>();
	
	String jj, jjType;
	List<String> gh1= new ArrayList<String>();
	
	public LoadDBImportWizard() {
		// TODO Auto-generated constructor stub
		this.setWindowTitle("Load Data from DataBase");
//		this.setDefaultPageImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/eclipse.png"));
		
	}

	@Override
	public boolean performFinish() {
		// TODO Auto-generated method stub
		LoadDBImportWizardPage loadDBPage = (LoadDBImportWizardPage)getPage("LoadDBImportWizardPage");
		String selectedValue = loadDBPage.getSelectedProject();
		String[] strSelectedValues = selectedValue.split("!@!");
		
		DBConnection dbConnection = new DBConnection();
		con = dbConnection.connection();
		
		try {
			stmt = con.createStatement();
			stmtRef = con.createStatement();
			stmtMarker = con.createStatement();
			stmtAcc = con.createStatement();
			stmtAllele = con.createStatement();
			stmtMap = con.createStatement();
			stmtQTL = con.createStatement();
			stmtSelAcc = con.createStatement();
			stmtTargetGeno = con.createStatement();
			stmtTargetGeno1 = con.createStatement();
			stmtTargetAllele = con.createStatement(); 
			
			FileOutputStream fout = null;
			FileOutputStream fOutMap = null;
			FileOutputStream fOutQTL = null;
			PrintStream bout = null;
			PrintStream bout1 = null;
			PrintStream printMapDetails = null;
			PrintStream printQTLDetails = null;
			
			
			
			rs = stmt.executeQuery("select project.project_id, gen.generation_id, gen.ploidy, gen.dataset_id from project_details project inner join generation_details gen on project.project_id = gen.project_id where project.project_name='"+strSelectedValues[0]+"' and gen.generation_name='"+strSelectedValues[1]+"'");
			while(rs.next()){
				projectId = rs.getInt("project_id");
				generationId = rs.getInt("generation_id");
				ploidy = rs.getInt("ploidy");
				datasetId = rs.getString("dataset_id");
			}
			
			/**
			 * For Genotype_File.....
			 **/
			
			rsRef = stmtRef.executeQuery("select * from reference where generation_id='"+generationId+"' order by accession_id");
			while(rsRef.next()){
				strLink = rsRef.getInt("accession_id")+"@@"+rsRef.getInt("marker_id")+"@@"+rsRef.getInt("allelevalue_id");
				completeList.add(strLink);
				accIdHashSet.add(rsRef.getInt("accession_id"));
				markerIdHashSet.add(rsRef.getInt("marker_id"));
			}
			
			for(Iterator<Integer> it = accIdHashSet.iterator(); it.hasNext();){
				accIdList.add(it.next());
				
			}

			
			try {
				folder = "C://ISMAB_TEMPFiles";
				if(!new File(folder).exists())
			       	new File(folder).mkdir();
				
				String genoFileName = folder+"//genotype.xls";
				genoTxtFile = folder+"//genotypetxt.txt";				
				linkageTxtFile = folder+"//mapFile.txt";	
				QTLTxtFile = folder+"//QTLFile.txt";
				
				
				fout = new FileOutputStream(genoTxtFile);
				bout = new PrintStream(fout);
				bout1 = new PrintStream(fout);
				
				fOutMap =  new FileOutputStream(linkageTxtFile);
				printMapDetails = new PrintStream(fOutMap);
				
				fOutQTL =  new FileOutputStream(QTLTxtFile);
				printQTLDetails = new PrintStream(fOutQTL);
				
				
				bout.append("DatasetID\tGenotype/Marker\t");
								
				
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			/**
			 * For sorting the ArrayList in Ascending Order....
			 **/
			Collections.sort(accIdList);		
			
			//try {
				
				int j = 2;
				int k = 2;
				int a = 1;
				String test = "";String test1 = "";
				for(int i = 0; i < completeList.size(); i++){
					String strCompList = completeList.get(i);					
					arrCompList = strCompList.split("@@");
					
					
					//For Markers...
					if(j < (markerIdHashSet.size() * ploidy)+ 2){	
						rsMarker = stmtMarker.executeQuery("select marker_name from markers where marker_id = '"+arrCompList[1]+"'");
						while(rsMarker.next()){							
							/*lbl = new Label(j, 0, rsMarker.getString("marker_name"), writeCell);						
							sheet.addCell(lbl);*/
							bout.append(rsMarker.getString("marker_name")+"\t");
							//bout.println(rsMarker.getString("marker_name")+"\t");
							j++;
						}
					}
					
					
					//For Allele Values....
					rsAllele = stmtAllele.executeQuery("select * from allele_integervalues where allelevalue_id = '"+arrCompList[2]+"'");					
					
					if(a < (accIdList.size()+1)){
						if(countChk > 0){
							k = 2;
							countChk = 0;
							
							test1 = "";
						}
						if(k < (markerIdHashSet.size() * ploidy)+ 3){
							while(rsAllele.next()){
								
								test1 = test1 +rsAllele.getInt("allele_value")+"\t";
								k++;								
							}
							if(k == ((markerIdHashSet.size() * ploidy)+ 3) - 1){
								countChk++;
								a++;
								test = test + arrCompList[0]+"="+test1+"!@@@!";							
								
							}
												
						}						
					}					
				}
				
				bout.append("\n");
				//For Accessions....
				
				for(int acc = 1; acc < accIdList.size()+1; acc++){
					
					bout1.print(datasetId+"\t");
					rsAcc = stmtAcc.executeQuery("select accession_name from accessions where accession_id = '"+accIdList.get(acc-1)+"'");
					while(rsAcc.next()){
									
						bout1.print(rsAcc.getString("accession_name")+"\t");
					}
					
					String[] test2 = test.split("!@@@!");
					
					for(int d=0;d<test2.length;d++){
						if(test2[d].startsWith(acc+"=")){
							bout1.println(test2[d].substring(test2[d].indexOf("=")+1));
						}
					}
				}
				
				
				GenotypeDataLoader gLoader = new GenotypeDataLoader();
				// for Genotype File Upload....
				RootModel gType = gLoader.loadGenotype(genoTxtFile);
				
				//Using Session Variables....
				Session.getInstance().setRootModel(gType);
				
				
				/**
				 * For Linkage_Map File.....
				 **/
				rsMap = stmtMap.executeQuery("select * from map_details where generation_id = '"+generationId+"'");
				while(rsMap.next()){
					printMapDetails.println(rsMap.getString("chromosome")+"\t"+rsMap.getString("marker_name")+"\t"+rsMap.getInt("marker_count")+"\t"+rsMap.getFloat("marker_position")+"\t"+rsMap.getFloat("cumulative_dist"));
					
				}
				
				LinkageMapDataLoader mapLoader= new LinkageMapDataLoader();
				RootModel gType1 = mapLoader.load(linkageTxtFile);
				
				// Using Session Variables.........
				Session.getInstance().setRootModel(gType1);
				
				/**
				 * For QTL File....
				 **/
				printQTLDetails.println("Name\tChromosome\tPosition\tPos-Min\tPos-Max\tTrait\tExperiment\tCLEN\tLFM\tPLFM\tRFM\tPFRM\tEffect\tLOD\tR2");
				rsQTL = stmtQTL.executeQuery("select * from qtl_details where generation_id='"+generationId+"'");
				while(rsQTL.next()){
					
					printQTLDetails.println(rsQTL.getString("qtl_name")+"\t"+rsQTL.getString("chromosome")+"\t"+rsQTL.getInt("position")+"\t"+rsQTL.getInt("start_pos")+"\t"+rsQTL.getInt("end_pos")+"\t"+rsQTL.getString("trait_name")+"\t"+rsQTL.getInt("experiment")+"\t\t\t\t\t\t"+rsQTL.getFloat("lod_score")+"\t"+rsQTL.getFloat("r2")+"\t"+rsQTL.getFloat("additive_effects"));
					
				}
				QTLDataLoader qtlLoader = new QTLDataLoader();
				RootModel qtlModel = qtlLoader.load(QTLTxtFile);
				Session.getInstance().setRootModel(qtlModel);
				
				/**
				 * For SelectedAccessions...
				 **/
				RootModel rootModel = Session.getInstance().getRootmodel();
				
				
				for(int sA = 0; sA < rootModel.getGenotype().get(0).getAccessions().size();sA++){
					selAccHashMap.put(rootModel.getGenotype().get(0).getAccessions().get(sA).getName(), rootModel.getGenotype().get(0).getAccessions().get(sA));
					selAccHashMap1.put(rootModel.getGenotype().get(0).getAccessions().get(sA).getName(), sA);
				}
				
				try {
					AccessionListView view1 = (AccessionListView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(AccessionListView.class.getName());
					SelectedAccessionsView subAcc = (SelectedAccessionsView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SelectedAccessionsView.class.getName());
					GraphicalView gView = (GraphicalView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(GraphicalView.class.getName());
					//IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find(GraphicalView.class.getName());
					//System.out.println("TESTING :::"+descr.getId());
					
					rsSelAcc = stmtSelAcc.executeQuery("select acc.accession_name, type.type_name from selected_accessions selAcc inner join accessions acc on selAcc.accession_id = acc.accession_id  inner join type_details type on type.type_id=selAcc.type_id where generation_id='"+generationId+"'");
					while(rsSelAcc.next()){
						//System.out.println(rsSelAcc.getString("accession_name")+"::::"+selAccHashMap.get(rsSelAcc.getString("accession_name")));
						selAccList.add(selAccHashMap.get(rsSelAcc.getString("accession_name")));
						rootModel.getGenotype().get(0).getAccessions().get(Integer.parseInt(selAccHashMap1.get(rsSelAcc.getString("accession_name")).toString())).setType(rsSelAcc.getString("type_name"));
						
					}
					
					//This sets the selection into Accession View......

					view1.getSite().getSelectionProvider().setSelection(new StructuredSelection(selAccList));
					
					//gView.getSite().getSelectionProvider().setSelection(new StructuredSelection(rootModel));
					
					Session.getInstance().setRootModel(rootModel);
					
					
					
					
					//gView.notifyLoad(RootModel.getRootModel());
					
					//Session.getInstance().setRootModel(rootModel);
					
					
					//For Target Genotype.....
					try{
						for(int tg = 0; tg < rootModel.getGenotype().get(0).getAccessions().size(); tg++){
							//System.out.println("Accession ::::"+rootModel.getGenotype().get(0).getAccessions().get(tg));
							for(int ii = 0; ii < rootModel.getGenotype().get(0).getAccessions().get(tg).getSelectedAccessions().size(); ii++){
								targetHashMap.put(rootModel.getGenotype().get(0).getAccessions().get(tg).getName(), rootModel.getGenotype().get(0).getAccessions().get(tg).getSelectedAccessions().get(ii).getSelacc1().get(0).getGenotypeMarkers());
								
								//GenotypeMarkers type1 = (GenotypeMarkers) rootModel.getGenotype().get(0).getAccessions().get(tg).getSelectedAccessions().get(ii).getSelacc1().get(0).getGenotypeMarkers();
								
								//EditPart editPart = (EditPart) gView.getGViewer().getEditPartRegistry().get(type);
								//ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart)((GraphicalViewer) gView).getEditPartRegistry().get(iterator.next());
								//editParts.add(editPart);
								//System.out.println("editParts ::"+editParts);
								
//								targetHashMap.put(rootModel.getGenotype().get(0).getAccessions().get(tg).getName(), rootModel.getGenotype().get(0).getAccessions().get(tg).getSelectedAccessions().get(ii).getSelacc1().get(0).getGenotypeMarkers().get(0).getEP());
							}
						}
						String testStr = "";String testStr2 ="";String testStr1 ="";
						Object obj = "";
						rsTargetGeno = stmtTargetGeno.executeQuery("select distinct acc.accession_name from target_genotype tg inner join accessions acc on tg.accession_id=acc.accession_id where generation_id='"+generationId+"'");
						while(rsTargetGeno.next()){
							//testStr1 = targetHashMap.get(rsTargetGeno.getString("accession_name"));
							//testStr2 = testStr1.substring(testStr1.indexOf("org"),testStr1.indexOf("]"));
							//testStr = "GMarkerEditPart( "+testStr2+" )";
							obj = targetHashMap.get(rsTargetGeno.getString("accession_name"));
							
							Object obj1 = ((ArrayList)obj).get(0);
//							testStr2 = testStr1.substring(testStr1.indexOf("GMarkerEditPart"),testStr1.indexOf("]"));
							
							//obj = testStr2;
							//ScrollingGraphicalViewer gv = (ScrollingGraphicalViewer) gView.getAdapter(GraphicalView.class);
							//GraphicalViewer gvv = (GraphicalViewer) gView.getAdapter(GraphicalViewer.class);
							//System.out.println("Load ImportWizard :: "+gvv);
							//EditPart editPart = (EditPart) gvv.getEditPartRegistry().get(testStr2);
							
							targetGenoList.add(obj1);					
						}
						//ScrollingGraphicalViewer viewer = getGraphicalViewer();
						//;
						
						rsTargetGeno1 = stmtTargetGeno1.executeQuery("select allelevalue_id from target_genotype where generation_id='"+generationId+"' and type_id='3'");
						while(rsTargetGeno1.next()){
							//System.out.println(rsTargetGeno1.getString("allelevalue_id"));
							rsTargetAllele = stmtTargetAllele.executeQuery("select allele_value from allele_integervalues where allelevalue_id='"+rsTargetGeno1.getString("allelevalue_id")+"'");
							while(rsTargetAllele.next()){
								targetAlleles.add(rsTargetAllele.getString("allele_value"));
							}
						}
						//System.out.println("Value :"+targetAlleles);
						for(int ta = 0; ta < targetAlleles.size(); ta++) {
							String combiAllele = targetAlleles.get(ta)+" "+targetAlleles.get(ta+1);
							targetCombAlleles.add(combiAllele);
							ta = ta+1;
						}
						//System.out.println("targetCombAlleles :"+targetCombAlleles);
						for (Iterator<Object> iterator = targetGenoList.iterator(); iterator.hasNext();) {
							//System.out.println("iterator.next() ::::"+(GenotypeMarkers)get);
							//viewer.getEditPartRegistry();
							GenotypeMarkers type = (GenotypeMarkers) iterator.next();
							//GenotypeMarkers type1 = ((GenotypeMarkers)getModel());
							//System.out.println("iterator::::"+getModel());
							//if(type1 !=null){
								
								
							EditPart editPart = (EditPart) gView.getGViewer().getEditPartRegistry().get(type);
							//ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart)((GraphicalViewer) gView).getEditPartRegistry().get(iterator.next());
							
							editParts.add(editPart);
							gView.getGViewer().setSelection(new StructuredSelection(editParts));
							
							//}
						}
						
						TargetGeno target = TargetGeno.getTargetGeno();
						for(int i = 0; i < target.getParents().size(); i++) {
							jj = target.getParents().get(i).getParent();
							String type = target.getParents().get(i).getType();
							if(type.equals("Recurrent")) {
								jjType = target.getParents().get(i).getParent();
							}							
						}
						
						/**
						 * Here I am creating a Combination of Markername+allelePair+colorLabel+parentType
						 * for Donor and Recurrent parents and setting it to model for further reference...
						 **/
						for(int loop = 0; loop < target.getParents().size(); loop++){
							int jk = target.getParents().get(0).getSelParents().size();
							int kk = target.getParents().get(0).getSelParents().get(0).getMParents().size();
							
							List<String> targetMarkers = target.getParents().get(loop).getSelParents().get(0).getMParents().get(0).getMarkerName();
							List<String> targetAlleles = target.getParents().get(loop).getSelParents().get(0).getMParents().get(0).getTargetAlleleValue();
							List<String> targetColorLabels = target.getParents().get(loop).getSelParents().get(0).getMParents().get(0).getLabel();
							
							
							if(target.getParents().get(loop).getSelParents().get(0).getMParents().get(0).getAccession() != null){
								for(int mar = 0; mar < target.getParents().get(loop).getSelParents().get(0).getMParents().get(0).getAccession().size() ; mar++){
									if(target.getParents().get(loop).getParent().equals(target.getParents().get(loop).getSelParents().get(0).getMParents().get(0).getAccession().get(mar))){
										String MAC_combiValues = targetMarkers.get(mar)+"::"+targetAlleles.get(mar)+"::"+targetColorLabels.get(mar)+"::"+target.getParents().get(loop).getType();
										targetMACCombiValues.add(MAC_combiValues);
									}
								}
							}
							
//							System.out.println("targetMACCombiValues :"+targetMACCombiValues);
							target.getParents().get(loop).getSelParents().get(jk-1).getMParents().get(kk-1).setTargetMACCombi(targetMACCombiValues);
						}
						
						
						/**
						 * At first target will be the copy of recurrent so here I am 
						 * creating the variables which are required in the creation of target...
						 **/
						int ii = 3;
						
						if(target.getParents().size() <= 3) {
							target.getParents().get(ii-1).setParent(jjType+"Target");
							int jk = target.getParents().get(0).getSelParents().size();
							List<String> chrName = rootModel.getChrNo();
							target.getParents().get(ii-1).getSelParents().get(jk-1).setSelectedParents(jjType+"Target");
							target.getParents().get(ii-1).setType("Target");
							target.getParents().get(ii-1).getSelParents().get(jk-1).setChrNo(chrName);
							int kk = target.getParents().get(0).getSelParents().get(0).getMParents().size();
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setSelectedParents(jjType+"Target");
							List<String> newAcc = rootModel.getAccession();
							List<String> markerName = rootModel.getMarkerName();
							List<Integer> markerPosition = rootModel.getMarkerPosition();
							List<Integer> markerPrevPos = rootModel.getMarkerPrevPos();
							List<Integer> markerNextPos = rootModel.getMarkerNextPos();
							List<String> label = rootModel.getLabel();
							List<String> allval = rootModel.getAccAllele();
							List<String> allval1 = targetCombAlleles;
							
							//System.out.println("allval1 :"+allval1);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setAccession(newAcc);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setChrNo(chrName);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setLabel(label);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setTargetAlleleValue(allval);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setTargetAlleleFrmDataBase(allval1);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setMarkerName(markerName);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setMarkerPosition(markerPosition);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setMarkerPrevPos(markerPrevPos);
							target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).setMarkerNextPos(markerNextPos);
							
//							System.out.println("MarkerName :"+target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).getMarkerName()+"::AlleleValue::"+target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).getTargetAlleleValue()+"::Label::"+target.getParents().get(ii-1).getSelParents().get(jk-1).getMParents().get(kk-1).getLabel());
							
							
							SessionTargetGenotype.getInstance().setTargetGeno(target);
							
						}
						//SessionTargetGenotype.getInstance().setTargetGeno(target);
						
						//Code...
						/*List<EditPart> editParts = new ArrayList<EditPart>();
						for (Iterator iterator = targetGenoList.iterator(); iterator.hasNext();) {
							<Ur Object> type = (<Ur Object>) iterator.next();
							EditPart editPart = (EditPart)    getGraphicalViewer().getEditPartRegistry().get(type);
							editParts.add(editPart);
						}
								
						getGraphicalViewer().setSelection(new StructuredSelection(editParts));*/

						
						//System.out.println("editParts ::"+editParts);
						//gView.getGViewer().setSelection(new StructuredSelection(editParts));

						
						
						//System.out.println("target ::"+target);
						//ISelection selection = (ISelection) targetGenoList;
						//IStructuredSelection selectedElements = ((IStructuredSelection) targetGenoList);
						
						//gView.get
						//gView.getSite().getSelectionProvider().setSelection(new StructuredSelection(targetGenoList));	
					}catch(Exception e){
						e.printStackTrace();
						
					}
					
				} catch (PartInitException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}				

				try {
					fout.close();
					bout.close();
					bout1.close();
					printMapDetails.close();
					printQTLDetails.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try{
				if(con!=null){
					con.close();					
				}
				
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e);
			}
		}	
		
		return true;
	}

	/*
	private GenotypeMarkers getModel() {
		// TODO Auto-generated method stub
	
		return genoMarkers;
	}

	private ScrollingGraphicalViewer getGraphicalViewer() {
		// TODO Auto-generated method stub
		return graphicalViewer;
	}*/


	public void init(IWorkbench workbench, IStructuredSelection selection) {
		// TODO Auto-generated method stub

	}
	
	@Override
	public void addPages() {
		// TODO Auto-generated method stub
		addPage(new LoadDBImportWizardPage("LoadDBImportWizardPage"));
	}

}
